package com.maybach.core.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.maybach.core.ao.OperateLogAO;
import com.maybach.dubbo.api.BizResult;
import com.maybach.dubbo.api.model.OperateLogModel;
import com.maybach.dubbo.api.service.IB2BOperateLogMngService;

import libs.fastjson.com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

/**
 * ${操作日志原子接口实现} Created by chris on 16/3/29. e-mail baijun@maihaoche.com
 */
@Component
@Slf4j
public class B2BOperateLogMngService implements IB2BOperateLogMngService {

	@Autowired
	OperateLogAO operateLogAO;

	@Override
	public BizResult<Long> createB2BOperateLog(OperateLogModel model) {
		try {
			Long logId = operateLogAO.addOperateLog(model);
			if (logId > 0) {
				return BizResult.create(logId);
			} else {
				return BizResult.create("501", "Insert op log error.");
			}
		} catch (Exception e) {
			log.error("Create op log error.\nParam is " + JSON.toJSONString(model), e);
			return BizResult.create("500", "Exception happens.");
		}
	}

	@Override
	public BizResult<Boolean> updateB2BOperateLog(OperateLogModel model) {
		try {
			return BizResult.create(operateLogAO.updateOperateLog(model));
		} catch (Exception e) {
			log.error("Update op log error.\nParam is " + JSON.toJSONString(model), e);
			return BizResult.create("500", "Exception happens.");
		}
	}

}
